package com.taoyibao.hongcanting.ui.mine.delegate;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.BackToolbarDelegate;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.ToastUtils;
import com.taoyibao.hongcanting.widget.AmountEditText;

/**
 * @author TangAnna
 * @description: 提现
 * @date :${DATA} 15:28
 */
public class WithdrawDelegate extends BackToolbarDelegate {

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_withdraw;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setTitle("提现");
    }

    /**
     * 获取支付宝账号
     *
     * @return
     */
    public String getAccount() {
        if (TextUtils.isEmpty(((EditText) get(R.id.et_withdraw_account)).getText().toString().trim())) {
            ToastUtils.showToast(CodeUtils.getIdString(R.string.string_hintInputRightAccount));
            return "";
        }
        return ((EditText) get(R.id.et_withdraw_account)).getText().toString().trim();
    }

    /**
     * 获取提现金额
     *
     * @return 0:输入金额不合法
     */
    public double getAmount() {
        String trim = ((AmountEditText) get(R.id.et_withdraw_amount)).getText().toString().trim();
        if (TextUtils.isEmpty(trim)) {
            ToastUtils.showToast(CodeUtils.getIdString(R.string.string_hintInputRightAmount));
            return 0;
        }
        try {
            double amount = Double.parseDouble(trim);
            return amount;
        } catch (Exception e) {
            ToastUtils.showToast(CodeUtils.getIdString(R.string.string_hintInputRightAmount));
            return 0;
        }
    }

    /**
     * 提现成功之后更新UI
     */
    public void setSuccess() {
        get(R.id.tv_withdraw_success).setVisibility(View.VISIBLE);
        ((Button) get(R.id.btn_withdraw_confirm)).setText(CodeUtils.getIdString(R.string.string_complete));
        ((EditText) get(R.id.et_withdraw_account)).setFocusable(false);
        ((AmountEditText) get(R.id.et_withdraw_amount)).setFocusable(false);
    }

    /**
     * 获取下面按钮上的文字
     *
     * @return
     */
    public String getButtonText() {
        return ((Button) get(R.id.btn_withdraw_confirm)).getText().toString().trim();
    }
}
